package demo;

class Food {
}
class Fruit extends Food {
}
class Apple extends Fruit {
}
class Banana extends Fruit {
}

class Message<T> {
    private T message ;
    public T getMessage() {
        return message;
    }
    public void setMessage(T message) {
        this.message = message;
    }
}


public class Test {

    /*public static void main3(String[] args) {
        Message<Apple> message1 = new Message<>();
        message1.setMessage(new Apple());
        Message<Banana> message2 = new Message<>();
        message2.setMessage(new Banana());
        fun(message1);
        fun(message2);
    }*/

    public static void main(String[] args) {
        Message<Fruit> message1 = new Message<>();
        message1.setMessage(new Fruit());
        Message<Food> message2 = new Message<>();
        message2.setMessage(new Food());
        fun(message1);
        fun(message2);
    }



    /*public static void main1(String[] args) {
        Message<String> message = new Message<>() ;
        message.setMessage("比特就业课欢迎您");
        fun(message);
    }*/

    public static void main2(String[] args) {
        Message<Integer> message2= new Message<>() ;
        message2.setMessage(123);
        fun2(message2);
    }

    public static void fun(Message<? super Fruit> temp){
        temp.setMessage(new Banana());
        temp.setMessage(new Apple());

        //Fruit fruit = temp.getMessage();
    }

    public static void fun3(Message<? extends Fruit> temp){
        System.out.println(temp.getMessage());
    }

    public static void fun2(Message<?> temp){
     //temp.setMessage(100); 无法修改！
        System.out.println(temp.getMessage());
    }
}

